﻿using RndMaterialDisposalService.Models;
using RndMaterialDisposalService.Models.Entitys;
using RndMaterialDisposalService.Models.RequestModel;
using AutoMapper;
using System.Text.Json;

namespace RndMaterialDisposalService.AutoMapperProfile
{
    /// <summary>
    /// 
    /// </summary>
    public class CapitalTransferReportProfile : Profile
    {
        /// <summary>
        /// 
        /// </summary>
        public CapitalTransferReportProfile()
        {
            CreateMap<CapitalTransferElectronFlowReq, CapitalTransferBusinessDataModel>()
                .ForMember(dest => dest.SysId, opt => opt.MapFrom(src => Guid.NewGuid().ToString("N")))
                .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")))
                .ForMember(dest => dest.ProcessFolio, opt => opt.MapFrom(src => src.FormHeader.ProcFolio.Trim()))
                .ForMember(dest => dest.ProcInstId, opt => opt.MapFrom(src => src.FormHeader.ProcInstId))
                .ForMember(dest => dest.OutDeptFirstDept, opt => opt.MapFrom(src => src.OutDept.DeptName))
                .ForMember(dest => dest.OutDeptSecondDept, opt => opt.MapFrom(src => src.OutDept.DeptName2))
                .ForMember(dest => dest.OutDeptUserID, opt => opt.MapFrom(src => src.OutDept.UserIDItem!.EmployeeNumber))
                .ForMember(dest => dest.OutDeptUserName, opt => opt.MapFrom(src => src.OutDept.UserIDItem!.Cname))
                .ForMember(dest => dest.OutDeptFirstAdminID, opt => opt.MapFrom(src => src.OutDept.FirstAdminItem!.ItemValue))
                .ForMember(dest => dest.LeaveTransfer, opt => opt.MapFrom(src => src.OutDept.LeaveTransfer == 1 ? "离职转移" : "非离职转移"))
                .ForMember(dest => dest.PCDataClear, opt => opt.MapFrom(src => src.OutDept.PCDataClearItem!.Label))
                .ForMember(dest => dest.InputDeptUserID, opt => opt.MapFrom(src => src.InputDept.UserIDItem!.EmployeeNumber))
                .ForMember(dest => dest.InputDeptFirstDept, opt => opt.MapFrom(src => src.InputDept.DeptName))
                .ForMember(dest => dest.InputDeptSecondDept, opt => opt.MapFrom(src => src.InputDept.DeptName2))
                .ForMember(dest => dest.InputDeptUserName, opt => opt.MapFrom(src => src.InputDept.UserIDItem!.Cname))
                .ForMember(dest => dest.InputDeptFirstAdminID, opt => opt.MapFrom(src => src.InputDept.FirstAdminItem!.ItemValue))
                .ForMember(dest => dest.Sparepart, opt => opt.MapFrom(src => src.OutDept.Sparepart));


            CreateMap<ERPAssetInfoModel, CapitalTransferBusinessSubtableDataModel>()
                 .ForMember(dest => dest.SysId, opt => opt.MapFrom(src => Guid.NewGuid().ToString("N")))
                 .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")))
                 //.ForMember(dest => dest.ProcInstId, opt => opt.MapFrom(src => src.FormHeader.ProcInstId))
                 .ForMember(dest => dest.AssetNo, opt => opt.MapFrom(src => src.AssetNumber))
                 .ForMember(dest => dest.AssetName, opt => opt.MapFrom(src => src.AssetDesription))
                 .ForMember(dest => dest.UserName, opt => opt.MapFrom(src => src.AssetOwnerName))
                 .ForMember(dest => dest.UserId, opt => opt.MapFrom(src => src.OwnerEmployeeNumber))
                 .ForMember(dest => dest.DepartmentName, opt => opt.MapFrom(src => src.DeptName))
                 .ForMember(dest => dest.DepartmentNumber, opt => opt.MapFrom(src => src.DeptNumber))
                 .ForMember(dest => dest.StorageLocation, opt => opt.MapFrom(src => $"{src.Location} {src.City}"))
                 .ForMember(dest => dest.ProductSegment, opt => opt.MapFrom(src => src.ProductLine));


            CreateMap<UserMiddleDto, WeixinUserReq>()
                .ForMember(dest => dest.UserId, opt => opt.MapFrom(src => src.EmployeeId))
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.UserName));


            CreateMap<UserMiddleDto, WeixinUserSyncLogDto>()
                .ForMember(dest => dest.UserId, opt => opt.MapFrom(src => src.EmployeeId))
                .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => DateTime.Now))
                .ForMember(dest => dest.Result, opt => opt.MapFrom((src, dest) => src.Status == 3 ? src.ErrorMsg : "success"))
                .ForMember(dest => dest.JsonData, opt => opt.MapFrom((src, dest) => JsonSerializer.Serialize(src)));

        }
    }
}
